<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/inc/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="decorator" content="main" />
<script type="text/javascript">
$(document).ready(function() {
	$("#tt").tree({
	url : '${ctx}/column/columnview.do?method=load',
	onClick : function(node) {
			var pnode=$('#tt').tree('find', node.pid);
			if(pnode==null){
				$("input[name='pname']").val("已是顶级栏目");
			}else{
				$("input[name='pname']").val(pnode.text);
			}
		//	window.location.href = url;
			$.post('${ctx}/column/columnview.do?method=ajaxinitForm&columnid='
					+ node.id,
					   function(data){
							$(".span9 .widgettitle").text("现在可修改栏目信息并在底部提交");
							 $("input[name='id']").val(data.id);
							 $("input[name='ppid']").val(data.ppid);
				             $("input[name='name']").val(data.name);
				             $("input[name='alias']").val(data.alias);
				             $("input[name='type']").val(data.type);
				             $("input[name='desciption']").val(data.desciption);
				             $("input[name='kw']").val(data.kw);
				             $("input[name='seodesc']").val(data.seodesc);
				             $("input[name='seotitle']").val(data.seotitle);
				             var status = data.status;
				             if(status=="Y"){
				            	 $("#selecter").val("Y");
				             }
				             else{
				            	 $("#selecter").val("N");
				             }
					   });
		},
	onContextMenu: function(e, node){
		e.preventDefault();
		// 选择节点
		$('#tt').tree('select', node.target);
		// 显示上下文菜单
		$('#mm').menu('show', {
			left: e.pageX,
			top: e.pageY
		});
	}
	});
	
});

function tianjia(){
	var node = $('#tt').tree('getSelected');
	var pnode=$('#tt').tree('find', node.pid);
	if(pnode==null){
		$("input[name='pname']").val("已是顶级栏目");
	}else{
		$("input[name='pname']").val(pnode.text);
	}
	
	$.post('${ctx}/column/columnview.do?method=ajaxAddForm&columnid='
			+ node.id,
			$("input[name='pname']").val(node.text),
			function(data){
				$(".span9 .widgettitle").text("现在可添加栏目信息并在底部提交");
				 $("input[name='id']").val(0);
				 $("input[name='ppid']").val(data.ppid);
				 $("input[name='name']").val(data.name);
	             $("input[name='alias']").val(data.alias);
	             $("input[name='type']").val(data.type);
	             $("input[name='desciption']").val(data.desciption);
	             $("input[name='kw']").val(data.kw);
	             $("input[name='seodesc']").val(data.seodesc);
	             $("input[name='seotitle']").val(data.seotitle);
	             var status = data.status;
	             if(status=="Y"){
	            	 $("#selecter").val("Y");
	             }
	             else{
	            	 $("#selecter").val("N");
	             }
	});
}

function shanchu(){
	var node = $('#tt').tree('getSelected');
	if (node.target){
		var id = node.id;
		console.log(node.children);
		if(node.children==undefined||node.children==""){
			delInfo(id);
		}else{
			alert("该目录下包含子目录，直接删除会造成严重后果，请逐一删除子目录后再进行此操作");
		}
	}
}

function delInfo(id) {
	var url = '${ctx}/column/columnview.do';
	$.messager.confirm('确认', '您确认想要删除此栏目吗？', function(r) {
		if (r) {
			$.ajax({
				type : "POST",
				url : url,
				data : 'method=del&columnid=' + id,
				success : function(dto) {
					$.messager.alert('警告', dto.msg);
					var node = $('#tt').tree('getSelected');
					$('#tt').tree('remove', node.target);
				}
			});
		}
	});
}

</script>
<title>栏目修改</title>
</head>
<body>
<div id="mm" class="easyui-menu" style="width:120px;">
	<div onclick="tianjia()">添加</div>
	<div onclick="shanchu()">删除</div>
</div>

	<ul class="breadcrumbs">
		<li><a href="${ctx}/login/LoginIndexRequestServlet.do"><i
				class="iconfa-home"></i></a> <span class="separator"></span></li>
		<li>栏目管理</li>
	</ul>
	<div>
		<div class="maincontent">
			<div class="maincontentinner">
				<div class="row-fluid">
					<div class="span3">
						<div class="widget">
							<h4 class="widgettitle">栏目列表</h4>
							<div class="widgetcontent">
								<ul id="tt"></ul>
							</div>
						</div>
					</div>

					<div class="span9">
						<div class="widget">
							<h4 class="widgettitle">选中左侧栏目以显示具体信息</h4>
							<div class="widgetcontent">
								<form id="ff" action="${ctx}/column/columnview.do">
									<input  name="method" type="hidden"
										value="addorup"></input> 
									<input  class="input-large" type="hidden" type="text" name="id" id="inputid"
										></input>
									<p style="padding-left: 260px">
										<input class="input-large"  type="hidden" type="text" 
											 name="ppid" data-options="required:true"
											></input>
									</p>
									<p style="padding-left: 260px">
										<label>上级栏目 :</label> <input class="input-large" type="text"
											 name="pname" data-options="required:true"
											></input>
									</p>
									<p style="padding-left: 260px">
										<label>栏目名称 :</label> <input class="input-large" type="text"
											 name="name" data-options="required:true"
											></input>
									</p>
									<p style="padding-left: 260px">
										<label>栏目简称:</label> <input class="input-large" type="text"
											name="alias" data-options="required:true"
											></input>
									</p>
									<p style="padding-left: 260px">
										<label>栏目类型:</label> <input class="input-large" type="text"
											name="type" data-options="required:true"
											></input>
									</p>
									<p style="padding-left: 260px">
										<label>栏目描述:</label> <input class="input-large" type="text"
											name="desciption" data-options="required:true"
											></input>
									</p>
									<p style="padding-left: 260px">
										<label>栏目图标:</label> <input class="input-large" type="text"
											name="logo" data-options="required:true"
											></input>
									</p>
									<p style="padding-left: 260px">
										<label>栏目关键字:</label> <input class="input-large" type="text"
											name="kw" data-options="required:true"
											></input>
									</p>
									<p style="padding-left: 260px">
										<label>SEO描述:</label> <input class="input-large" type="text"
											name="seodesc" data-options="required:true"
											></input>
									</p>
									<p style="padding-left: 260px">
										<label>SEO题目:</label> <input class="input-large" type="text"
											name="seotitle" data-options="required:true"
											></input>
									</p>
									<p style="padding-left: 260px">
										<label>状态:</label>
											<select name="status" id="selecter"
												style="height: 30px">
												<option value="Y">启用</option>
												<option value="N">禁用</option>
											</select>
									</p>
									<p class="stdformbutton" style="padding-left: 260px">
										<input type="submit" class="btn btn-primary" value="提交"></input>
										<input type="reset" class="btn" value="重置"></input>
									</p>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<!-- 
		<div id="p2">
			<form id="ff" action="columnadmin.do">
				<input type="hidden" name="method"
					value="${columninfo.id==0?'insert':'update'}"> <input
					type="hidden" class="input-large" type="text" name="id"
					value="${columninfo.id}"></input>
				<div style="margin: 10px 0 20px 200px">
					<label>状态:</label>
					<c:if test="${columninfo.status=='Y'}">
						<select class="easyui-combobox" name="status" value="Y">
							<option value="Y" selected="selected">启用</option>
							<option value="N">禁用</option>
						</select>
					</c:if>
					<c:if test="${columninfo.status!='Y'}">
						<select class="easyui-combobox" name="status" value="N">
							<option value="Y">启用</option>
							<option value="N" selected="selected">禁用</option>
						</select>
					</c:if>
				</div>
				<div style="margin: 10px 0 20px 200px">
					<label>栏目名称 :</label> <input class="input-large" type="text"
						name="name" data-options="required:true"
						value="${columninfo.name }"></input>
				</div>
				<div style="margin: 10px 0 20px 200px">
					<label>栏目简称:</label> <input class="input-large" type="text"
						name="alias" data-options="required:true"
						value="${columninfo.alias }"></input>
				</div>
				<div style="margin: 10px 0 20px 200px">
					<label>栏目类型:</label> <input class="input-large" type="text"
						name="type" data-options="required:true"
						value="${columninfo.type }"></input>
				</div>
				<div style="margin: 10px 0 20px 200px">
					<label>栏目描述:</label> <input class="input-large" type="text"
						name="desciption" data-options="required:true"
						value="${columninfo.desciption }"></input>
				</div>
				<div style="margin: 10px 0 20px 200px">
					<label>栏目图标:</label> <input class="input-large" type="text"
						name="logo" data-options="required:true"
						value="${columninfo.logo }"></input>
				</div>
				<div style="margin: 10px 0 20px 200px">
					<label>栏目关键字:</label> <input class="input-large" type="text"
						name="kw" data-options="required:true" value="${columninfo.kw }"></input>
				</div>
				<div style="margin: 10px 0 20px 200px">
					<label>SEO描述:</label> <input class="input-large" type="text"
						name="seodesc" data-options="required:true"
						value="${columninfo.seodesc }"></input>
				</div>
				<div style="margin: 10px 0 20px 200px">
					<label>SEO题目:</label> <input class="input-large" type="text"
						name="seotitle" data-options="required:true"
						value="${columninfo.seotitle }"></input>
				</div>
				<div style="margin: 10px 0 20px 200px">
					<label><input type="submit" value="提交" iconCls="icon-ok"></input>
					</label> <label><input type="reset" value="重置"></input></label>
				</div>
			</form>
		</div>
		 -->

	</div>
</body>
</html>